package Collection;

import java.util.Deque;
import java.util.LinkedList;

/**
 *双端队列 java.util.Deque接口
 * Deque继承自Queue，双端队列的特点是队列的两端都可以做出入对操作
 *
 */
public class DequeDemo {
    public static void main(String[] args) {
        Deque<String >deque=new LinkedList<>();
        deque.offer("one");
        deque.offer("two");
        deque.offer("three");
        deque.offer("four");
        System.out.println(deque);//[one, two, three, four]
        deque.offerFirst("zero");//从队首方向入队
        System.out.println(deque);//[zero, one, two, three, four]
        deque.offerLast("five");//从队尾方向入队
        System.out.println(deque);//[zero, one, two, three, four, five]
        System.out.println("------------------------------------");
        deque.pollFirst();
        System.out.println(deque);
        deque.pollLast();
        System.out.println(deque);


        String arr=deque.poll();//队首出队
        System.out.println(arr);
        System.out.println(deque);
        arr=deque.pollLast();//队尾出列
        System.out.println(arr);
        System.out.println(deque);
        arr=deque.pollFirst();//队首出列
        System.out.println(arr);
        System.out.println(deque);
        arr=deque.peekLast();
        System.out.println(arr);
        arr=deque.peekFirst();
        System.out.println(deque);

    }
}
